﻿Imports System.Drawing
Imports System.Drawing.Drawing2D
Imports System.Windows.Forms
Imports C1.Win.C1FlexGrid
Imports C1.Win.C1Input
Imports DevExpress.Utils.Drawing.Helpers

Namespace Componet
    ''' <summary>
    ''' 创建时间:2017/5/14
    ''' 说明：主题类型  
    ''' </summary>
    ''' <remarks></remarks>
    Public Enum Theme
        Office2003 = 2
        Office12 = 3
        Office10Blue = 41
    End Enum
    '    ''' <summary>
    '    ''' 创建时间：2017/5/1
    '    ''' 说明：单元格格式类型  
    '    ''' </summary>
    '    ''' <remarks>1=表格冻结，2=表格标题</remarks>
    '    Public Enum CellType
    '        ''' <summary>
    '        ''' 说明：单元格冻结(浅蓝色底)  
    '        ''' </summary>
    '        ''' <remarks></remarks>
    '        HCellLock = 1
    '        ''' <summary>
    '        ''' 说明：表格重要的标题栏，或者是重要行(深蓝色，白色字体)  
    '        ''' </summary>
    '        ''' <remarks></remarks>
    '        hCellImportTitle = 2
    '    End Enum
    ''' <summary>
    ''' 创建时间：2017/4/16
    ''' 说明：Flexgrid表格控件参数类  
    ''' </summary>
    ''' <remarks></remarks>
    Public Class FlexGridLib
        Inherits ConfigLib
        Private _flex As C1FlexGrid


        ''' <summary>
        ''' 创建时间：2017/5/17
        ''' 说明：重构函数  
        ''' </summary>
        ''' <param name="vFg">对应c1flexgrid参数</param>
        ''' <remarks></remarks>
        Public Sub New( vFg As C1FlexGrid)
            _flex = vfg
        End Sub
#Region "类参数及属性设置"
        public Property MErrMessage As String

#End Region
#Region "类的过程及函数设置"



        ''' <summary>
        ''' 创建时间：2017/4/3
        ''' 功能：根据字段名返回绑定字段所在列号   
        ''' </summary>
        ''' <param name="vFieldName">绑定的字段名</param>
        ''' <returns>返回列号</returns>
        ''' <remarks></remarks>
        Public Function ColIndex(ByVal vFieldName As String) As Integer
            Dim intIndex As Integer
            On Error GoTo herr
            intIndex = -1
            With _flex
                For i As Integer = 1 To .Cols.Count
                    If LCase(.Cols(i).Name) = LCase(vFieldName) Then
                        intIndex = i
                        GoTo herr
                    End If
                Next
            End With
herr:
            Return intIndex
        End Function

        ''' <summary>
        ''' 创建时间：2017/4/3
        ''' 功能：绑定数据源到flexgrid,通过TableName设置从f_columnlib提取字段配置信息  
        ''' </summary>
        ''' <param name="vFldDt">字段配置信息组成数据DataTable</param>
        ''' <param name="vLockColor">列只读是否设置背景颜色</param>
        ''' <remarks></remarks>
        Public Sub BindData(ByVal vFldDt As DataTable, Optional vLockColor As Long = 0)

            With _flex
                .Redraw = False

                .AutoGenerateColumns = False
                .Cols.Count = vFldDt.Rows.Count + 1 '//先设置列数

                .Rows.Count = 1
                .Rows(0).TextAlign = TextAlignEnum.CenterCenter

                For i As Integer = 0 To vFldDt.Rows.Count - 1
                    .Cols(i + 1).Caption = vFldDt.Rows(i)("col_Caption").ToString()
                    .Cols(i + 1).Name = vFldDt.Rows(i)("Col_FieldName").ToString()
                    .Cols(i + 1).Width = Convert.ToInt32(vFldDt.Rows(i)("col_width").ToString())
                    If vFldDt.Rows(i)("Col_ReadOnly").ToString() = "1" Then

                        '           Dim cs As CellStyle = _Flex.Styles.Add("Lock")
                        '          cs.DataType = GetType(String)

                        '      .Cols(i + 1).Style = cs
                        .Cols(i + 1).DataType = GetType(String)
                        .Cols(i + 1).AllowEditing = False
                        .Cols(i + 1).TextAlign = TextAlignEnum.LeftCenter

                        If vLockColor = 1 Then
                            '                            cs.BackColor = Color.AliceBlue
                            '                            cs.ForeColor = Color.MidnightBlue
                            .Cols(i + 1).StyleNew.BackColor = Color.AliceBlue
                            .Cols(i + 1).StyleNew.ForeColor = Color.MidnightBlue
                        End If
                    End If
                    If vFldDt.Rows(i)("Col_Visible").ToString() = "0" Then
                        .Cols(i + 1).Visible = False
                    End If
                    '//数字类型
                    If vFldDt.Rows(i)("Col_Number").ToString = "1" And vFldDt.Rows(i)("Col_CheckBox").ToString = "0" Then
                        '                        Dim cs As CellStyle = _Flex.Styles.Add("Number")
                        '                        cs.DataType = GetType(Decimal)
                        '                        cs.Format = "0.00"
                        '                        .Cols(i + 1).Style = cs
                        .Cols(i + 1).DataType = GetType(Decimal)
                        .Cols(i + 1).Format = String.Format("N{0}", vFldDt.Rows(i)("col_decimal").ToString)

                    End If
                    If vFldDt.Rows(i)("Col_CheckBox").ToString = "1" Then
                        '                        Dim cs As CellStyle = _Flex.Styles.Add("bool")
                        '                        cs.DataType = GetType(Boolean)
                        '                        cs.ImageAlign = ImageAlignEnum.CenterCenter
                        '
                        '                        .Cols(i + 1).Style = cs
                        .Cols(i + 1).ImageAlign = ImageAlignEnum.CenterCenter
                        .Cols(i + 1).DataType = GetType(Boolean)
                    End If
                    ‘//如果显示百分比 2023.4.7
                    if vFldDt.Rows(i)("col_windows").ToString.Contains("%")=true Then
                        .Cols(i + 1).DataType = GetType(Decimal)
                        .Cols(i + 1).Format ="p"' String.Format("N{0}", vFldDt.Rows(i)("col_decimal").ToString)
                    End If
                Next


                .Redraw = True
            End With

        End Sub

        ''' <summary>
        ''' 创建时间：2017/4/3
        ''' 功能：绑定数据源到flexgrid,通过TableName设置从f_columnlib提取字段配置信息  
        ''' </summary>
        ''' <param name="vFldDt">字段配置信息组成数据DataTable</param>
        ''' <param name="vSourceData">数据DataTable</param>
        ''' <param name="vLockColor">列只读是否设置背景颜色</param>
        ''' <remarks></remarks>
        Public Sub BindData(ByVal vFldDt As DataTable, ByVal vSourceData As DataTable, Optional vLockColor As Long = 0)

            With _flex
                .Redraw = False

                .AutoGenerateColumns = False
                .Rows(0).TextAlign = TextAlignEnum.CenterCenter

                For i As Integer = 0 To vFldDt.Rows.Count - 1
                    .Cols(i + 1).TextAlign = TextAlignEnum.LeftCenter '文字排在右侧 2021.7.25
                    .Cols(i + 1).Caption = vFldDt.Rows(i)("col_Caption").ToString()
                    .Cols(i + 1).Name = vFldDt.Rows(i)("Col_FieldName").ToString()
                    .Cols(i + 1).Width = Convert.ToInt32(vFldDt.Rows(i)("col_width").ToString())
                    If vFldDt.Rows(i)("Col_ReadOnly").ToString() = "1" Then

                        '           Dim cs As CellStyle = _Flex.Styles.Add("Lock")
                        '          cs.DataType = GetType(String)

                        '      .Cols(i + 1).Style = cs
                        .Cols(i + 1).DataType = GetType(String)
                        .Cols(i + 1).AllowEditing = False
                        .Cols(i + 1).TextAlign = TextAlignEnum.LeftCenter

                        If vLockColor = 1 Then
                            '                            cs.BackColor = Color.AliceBlue
                            '                            cs.ForeColor = Color.MidnightBlue
                            .Cols(i + 1).StyleNew.BackColor = Color.AliceBlue
                            .Cols(i + 1).StyleNew.ForeColor = Color.MidnightBlue
                        End If
                    End If
                    If vFldDt.Rows(i)("Col_Visible").ToString() = "0" Then
                        .Cols(i + 1).Visible = False
                    End If
                    '//数字类型
                    If vFldDt.Rows(i)("Col_Number").ToString = "1" And vFldDt.Rows(i)("Col_CheckBox").ToString = "0" Then
                        '                        Dim cs As CellStyle = _Flex.Styles.Add("Number")
                        '                        cs.DataType = GetType(Decimal)
                        '                        cs.Format = "0.00"
                        '                        .Cols(i + 1).Style = cs
                        .Cols(i + 1).DataType = GetType(Decimal)
                        .Cols(i + 1).Format = String.Format("N{0}", vFldDt.Rows(i)("col_decimal").ToString)

                    End If
                    If vFldDt.Rows(i)("Col_CheckBox").ToString = "1" Then
                        '                        Dim cs As CellStyle = _Flex.Styles.Add("bool")
                        '                        cs.DataType = GetType(Boolean)
                        '                        cs.ImageAlign = ImageAlignEnum.CenterCenter
                        '
                        '                        .Cols(i + 1).Style = cs
                        .Cols(i + 1).ImageAlign = ImageAlignEnum.CenterCenter
                        .Cols(i + 1).DataType = GetType(Boolean)
                    End If
                    ‘//如果显示百分比 2023.4.7
                    if vFldDt.Rows(i)("col_windows").ToString.Contains("%")=true Then
                        .Cols(i + 1).DataType = GetType(Decimal)
                        .Cols(i + 1).Format ="p"' String.Format("N{0}", vFldDt.Rows(i)("col_decimal").ToString)
                    End If
                Next

                .Cols.Count = vFldDt.Rows.Count + 1
                .DataSource = vSourceData

                .Redraw = True
            End With

        End Sub
        ''' <summary>
        ''' 创建时间:2017/7/19
        ''' 说明：根据某个应用实例id下的模块名提取配置表中的字段清单，并把这些字段绑定到表格中  
        ''' </summary>
        ''' <param name="vFlex">c1flexgrid控件</param>
        ''' <param name="vSysid">应用实例id</param>
        ''' <param name="vModuleName">模块名，对应配置表f_columnlib.col_tablename</param>
        ''' <param name="vSourceData">需要加载到表格的内存库DataTable</param>
        ''' <param name="vConnection">数据库链接字符串</param>
        ''' <param name="vLockColor">锁定的表格是否显示背景颜色。0=不显示，1=显示</param>
        ''' <param name="vColumnIsSum">列项合计值是否计算，0=不计算，1=计算</param>
        ''' <remarks></remarks>
        Public Sub BindData(ByVal vFlex As C1FlexGrid, ByVal vSysid As String, ByVal vModuleName As String, ByVal vSourceData As DataTable, ByVal vConnection As String, Optional vLockColor As Long = 0, Optional vColumnIsSum As Long = 0)
            Dim vFldDt As New DataTable
            If Len(vSysid) = 0 Then
                vFldDt = ColumnLib(vModuleName, vConnection)
            Else
                vFldDt = ColumnLib(vSysid, vModuleName, vConnection)
            End If


            With vFlex
                .Redraw = False

                .AutoGenerateColumns = False
                .Cols.Count = 1
                .Cols.Count = vFldDt.Rows.Count + 1 '//先设置列数

                .Rows.Count = 1
                .Rows(0).TextAlign = TextAlignEnum.CenterCenter
                For i As Integer = 0 To vFldDt.Rows.Count - 1

                    .Cols(i + 1).AllowEditing = True
                    .Cols(i + 1).Caption = vFldDt.Rows(i)("col_Caption").ToString()
                    .Cols(i + 1).Name = vFldDt.Rows(i)("Col_FieldName").ToString()
                    .Cols(i + 1).Width = Convert.ToInt32(vFldDt.Rows(i)("col_width").ToString())

                    If vFldDt.Rows(i)("Col_ReadOnly").ToString() = "1" Then
                        '
                        .Cols(i + 1).AllowEditing = False
                        .Cols(i + 1).DataType = GetType(String)
                        .Cols(i + 1).TextAlign = TextAlignEnum.LeftCenter
                        If vLockColor = 1 Then
                            .Cols(i + 1).StyleNew.BackColor = Color.AliceBlue
                            .Cols(i + 1).StyleNew.ForeColor = Color.MidnightBlue
                        End If


                    End If
                    If vFldDt.Rows(i)("Col_Visible").ToString() = "0" Then
                        .Cols(i + 1).Visible = False
                    End If
                    '//数字类型
                    If vFldDt.Rows(i)("Col_Number").ToString = "1" And vFldDt.Rows(i)("Col_CheckBox").ToString = "0" Then
                        .Cols(i + 1).DataType = GetType(Decimal)
                        .Cols(i + 1).Format = String.Format("N{0}", vFldDt.Rows(i)("col_decimal").ToString)

                    End If
                    ‘//如果显示百分比 2023.4.7
                    if vFldDt.Rows(i)("col_windows").ToString.Contains("%")=true Then
                        .Cols(i + 1).DataType = GetType(Decimal)
                        .Cols(i + 1).Format ="p"' String.Format("N{0}", vFldDt.Rows(i)("col_decimal").ToString)
                    End If
                    If vFldDt.Rows(i)("Col_CheckBox").ToString = "1" Then
                        .Cols(i + 1).ImageAlign = ImageAlignEnum.CenterCenter
                        .Cols(i + 1).DataType = GetType(Boolean)

                    End If
                Next

                .Cols.Count = vFldDt.Rows.Count + 1
                .DataSource = vSourceData
                '//如果需要进行合计值计算

                If vColumnIsSum = 1 Then
                    FormulaSumTotal(vFlex, vModuleName, vConnection)
                End If
                .Redraw = True
            End With

        End Sub

        ''' <summary>
        ''' 创建时间:2017/7/14
        ''' 说明：根据某个应用实例id下的模块名提取配置表中的字段清单，并把这些字段绑定到表格中  
        ''' </summary>
        ''' <param name="vSysid">应用实例id</param>
        ''' <param name="vModuleName">模块名，对应配置表f_columnlib.col_tablename</param>
        ''' <param name="vSourceData">需要加载到表格的内存库DataTable</param>
        ''' <param name="vConnection">数据库链接字符串</param>
        ''' <param name="vLockColor">锁定的表格是否显示背景颜色。0=不显示，1=显示</param>
        ''' <param name="vColumnIsSum">列项合计值是否计算，0=不计算，1=计算</param>
        ''' <remarks></remarks>
        Public Sub BindData(ByVal vSysid As String, ByVal vModuleName As String, ByVal vSourceData As DataTable, ByVal vConnection As String, Optional vLockColor As Long = 0, Optional vColumnIsSum As Long = 0)
            Dim vFldDt As New DataTable
            vFldDt = ColumnLib(vSysid, vModuleName, vConnection)
            With _flex
                .Redraw = False

                .AutoGenerateColumns = False
                .Cols.Count = 1
                .Cols.Count = vFldDt.Rows.Count + 1 '//先设置列数

                .Rows.Count = 1
                .Rows(0).TextAlign = TextAlignEnum.CenterCenter

                For i As Integer = 0 To vFldDt.Rows.Count - 1

                    .Cols(i + 1).Caption = vFldDt.Rows(i)("col_Caption").ToString()
                    .Cols(i + 1).Name = vFldDt.Rows(i)("Col_FieldName").ToString()
                    .Cols(i + 1).Width = Convert.ToInt32(vFldDt.Rows(i)("col_width").ToString())
                    If vFldDt.Rows(i)("Col_ReadOnly").ToString() = "1" Then

                        Dim cs As CellStyle = _flex.Styles.Add("Lock")
                        cs.DataType = GetType(String)


                        .Cols(i + 1).Style = cs
                        .Cols(i + 1).AllowEditing = False
                        .Cols(i + 1).TextAlign = TextAlignEnum.LeftCenter

                        If vLockColor = 1 Then
                            cs.BackColor = Color.AliceBlue
                            cs.ForeColor = Color.MidnightBlue
                        End If
                    End If
                    If vFldDt.Rows(i)("Col_Visible").ToString() = "0" Then
                        .Cols(i + 1).Visible = False
                    End If
                    '//数字类型
                    If vFldDt.Rows(i)("Col_Number").ToString = "1" And vFldDt.Rows(i)("Col_CheckBox").ToString = "0" Then
                        Dim cs As CellStyle = _flex.Styles.Add("Number")
                        cs.DataType = GetType(Decimal)
                        cs.Format = "0.00"
                        .Cols(i + 1).Style = cs

                    End If
                    If vFldDt.Rows(i)("Col_CheckBox").ToString = "1" Then
                        Dim cs As CellStyle = _flex.Styles.Add("bool")
                        cs.DataType = GetType(Boolean)
                        cs.ImageAlign = ImageAlignEnum.CenterCenter

                        .Cols(i + 1).Style = cs

                    End If
                    ‘//如果显示百分比 2023.4.7
                    if vFldDt.Rows(i)("col_windows").ToString.Contains("%")=true Then
                        .Cols(i + 1).DataType = GetType(Decimal)
                        .Cols(i + 1).Format ="p"' String.Format("N{0}", vFldDt.Rows(i)("col_decimal").ToString)
                    End If
                Next

                .Cols.Count = vFldDt.Rows.Count + 1
                .DataSource = vSourceData
                '//如果需要进行合计值计算

                If vColumnIsSum = 1 Then

                    FormulaSumTotal(vModuleName, vConnection)
                End If
                .Redraw = True
            End With

        End Sub
        ''' <summary>
        ''' 创建时间:2017/4/16
        ''' 说明：根据模块名提取配置表中的字段清单，并把这些字段绑定到表格中  
        ''' </summary>
        ''' <param name="vFlex">c1flexgrid控件表格</param>
        ''' <param name="vModuleName">模块名，对应配置表f_columnlib.col_tablename</param>
        ''' <param name="vSourceData">需要加载到表格的内存库DataTable</param>
        ''' <param name="vConnection">数据库链接字符串</param>
        ''' <param name="vLockColor">锁定的表格是否显示背景颜色。0=不显示，1=显示</param>
        ''' <param name="vColumnIsSum">列项合计值是否计算，0=不计算，1=计算</param>
        ''' <remarks></remarks>
        Public Sub BindData(ByVal vFlex As C1FlexGrid, ByVal vModuleName As String, ByVal vSourceData As DataTable, ByVal vConnection As String, Optional vLockColor As Long = 0, Optional vColumnIsSum As Long = 0)
            BindData(vFlex, "", vModuleName, vSourceData, vConnection, vLockColor, vColumnIsSum)
        End Sub
        ''' <summary>
        ''' 创建时间:2017/4/16
        ''' 说明：根据模块名提取配置表中的字段清单，并把这些字段绑定到表格中  
        ''' </summary>
        ''' <param name="vModuleName">模块名，对应配置表f_columnlib.col_tablename</param>
        ''' <param name="vSourceData">需要加载到表格的内存库DataTable</param>
        ''' <param name="vConnection">数据库链接字符串</param>
        ''' <param name="vLockColor">锁定的表格是否显示背景颜色。0=不显示，1=显示</param>
        ''' <param name="vColumnIsSum">列项合计值是否计算，0=不计算，1=计算</param>
        ''' <remarks></remarks>
        Public Sub BindData(ByVal vModuleName As String, ByVal vSourceData As DataTable, ByVal vConnection As String, Optional vLockColor As Long = 0, Optional vColumnIsSum As Long = 0)
            BindData("", vModuleName, vSourceData, vConnection, vLockColor, vColumnIsSum)
        End Sub

        ''' <summary>
        ''' 创建时间:2017/7/14
        ''' 说明：根据某个应用实例下的模块名提取配置表中的字段清单，并把这些字段绑定到表格中  
        ''' </summary>
        ''' <param name="vSysid">应用实例id</param>
        ''' <param name="vModuleName">模块名，对应配置表f_columnlib.col_tablename</param>
        ''' <param name="vConnection">数据库链接字符串</param>
        ''' <param name="vLockColor">锁定的表格是否显示背景颜色。0=不显示，1=显示</param>
        ''' <remarks></remarks>
        Public Sub BindData(ByVal vSysid As String, ByVal vModuleName As String, ByVal vConnection As String, Optional vLockColor As Long = 0)
            Dim vFldDt As New DataTable
            vFldDt = ColumnLib(vSysid, vModuleName, vConnection)
            With _flex
                .Redraw = False

                .AutoGenerateColumns = False
                .Cols.Count = vFldDt.Rows.Count + 1 '//先设置列数

                .Rows.Count = 1
                .Rows(0).TextAlign = TextAlignEnum.CenterCenter

                For i As Integer = 0 To vFldDt.Rows.Count - 1

                    .Cols(i + 1).Caption = vFldDt.Rows(i)("col_Caption").ToString()
                    .Cols(i + 1).Name = vFldDt.Rows(i)("Col_FieldName").ToString()
                    .Cols(i + 1).Width = Convert.ToInt32(vFldDt.Rows(i)("col_width").ToString())
                    If vFldDt.Rows(i)("Col_ReadOnly").ToString() = "1" Then


                        .Cols(i + 1).DataType = GetType(String)
                        .Cols(i + 1).AllowEditing = False
                        .Cols(i + 1).TextAlign = TextAlignEnum.LeftCenter

                        If vLockColor = 1 Then
                            .Cols(i + 1).StyleNew.BackColor = Color.AliceBlue
                            .Cols(i + 1).StyleNew.ForeColor = Color.MidnightBlue
                        End If
                    End If
                    If vFldDt.Rows(i)("Col_Visible").ToString() = "0" Then
                        .Cols(i + 1).Visible = False
                    End If
                    '//数字类型
                    If vFldDt.Rows(i)("Col_Number").ToString = "1" And vFldDt.Rows(i)("Col_CheckBox").ToString = "0" Then
                        .Cols(i + 1).DataType = GetType(Decimal)
                        .Cols(i + 1).Format = String.Format("N{0}", vFldDt.Rows(i)("col_decimal").ToString)

                    End If
                    If vFldDt.Rows(i)("Col_CheckBox").ToString = "1" Then
                        .Cols(i + 1).ImageAlign = ImageAlignEnum.CenterCenter
                        .Cols(i + 1).DataType = GetType(Boolean)
                    End If

                Next


                .Redraw = True
            End With

        End Sub
        ''' <summary>
        ''' 创建时间:2017/4/16
        ''' 说明：根据模块名提取配置表中的字段清单，并把这些字段绑定到表格中  
        ''' </summary>
        ''' <param name="vModuleName">模块名，对应配置表f_columnlib.col_tablename</param>
        ''' <param name="vConnection">数据库链接字符串</param>
        ''' <param name="vLockColor">锁定的表格是否显示背景颜色。0=不显示，1=显示</param>
        ''' <remarks></remarks>
        Public Sub BindData(ByVal vModuleName As String, ByVal vConnection As String, Optional vLockColor As Long = 0)
            BindData("", vModuleName, vConnection, vLockColor)
        End Sub

        ''' <summary>
        ''' 创建时间:2017/7/19
        ''' 说明：根据某个应用实例下的模块名提取对表格样式celltype进行设置    
        ''' </summary>
        ''' <paran name="vflex">c1flexgrid控件</paran>
        ''' <param name="vSysid">应用实例id</param>
        ''' <param name="vModuleName">模块名，对应配置表f_columnlib.col_tablename</param>
        ''' <param name="vConnection">数据库链接字符串</param>
        ''' <param name="vLockColor">锁定的表格是否显示背景颜色。0=不显示，1=显示</param>
        ''' <remarks></remarks>
        Public Sub SetCellStyle(ByVal vFlex As C1FlexGrid, ByVal vSysid As String, ByVal vModuleName As String, ByVal vConnection As String, Optional vLockColor As Long = 0)
            Dim vFldDt As New DataTable
            vFldDt = ColumnLib(vSysid, vModuleName, vConnection)
            With vFlex

                For i As Integer = 0 To vFldDt.Rows.Count - 1
                    .Cols(i + 1).AllowEditing = True
                    If vFldDt.Rows(i)("Col_ReadOnly").ToString() = "1" Then

                        Dim cs As CellStyle = vFlex.Styles.Add("Lock")
                        cs.DataType = GetType(String)


                        .Cols(i + 1).Style = cs
                        .Cols(i + 1).AllowEditing = False
                        .Cols(i + 1).TextAlign = TextAlignEnum.LeftCenter

                        If vLockColor = 1 Then
                            cs.BackColor = Color.AliceBlue
                            cs.ForeColor = Color.MidnightBlue
                        End If
                    End If

                    If vFldDt.Rows(i)("Col_CheckBox").ToString = "1" Then
                        Dim cs As CellStyle = vFlex.Styles.Add("bool")
                        cs.DataType = GetType(Boolean)
                        cs.ImageAlign = ImageAlignEnum.CenterCenter

                        .Cols(i + 1).Style = cs
                    End If

                Next

            End With

        End Sub
        ''' <summary>
        ''' 创建时间:2017/7/19
        ''' 说明：根据某个应用实例下的模块名提取对表格样式celltype进行设置    
        ''' </summary>
        ''' <param name="vSysid">应用实例id</param>
        ''' <param name="vModuleName">模块名，对应配置表f_columnlib.col_tablename</param>
        ''' <param name="vConnection">数据库链接字符串</param>
        ''' <param name="vLockColor">锁定的表格是否显示背景颜色。0=不显示，1=显示</param>
        ''' <remarks></remarks>
        Public Sub SetCellStyle(ByVal vSysid As String, ByVal vModuleName As String, ByVal vConnection As String, Optional vLockColor As Long = 0)
            Dim vFldDt As New DataTable
            If Len(vSysid) = 0 Then
                vFldDt = ColumnLib(vModuleName, vConnection)
            Else
                vFldDt = ColumnLib(vSysid, vModuleName, vConnection)
            End If

            With _flex

                For i As Integer = 0 To vFldDt.Rows.Count - 1

                    .Cols(i + 1).AllowEditing = True
                    If vFldDt.Rows(i)("Col_ReadOnly").ToString() = "1" Then

                        Dim cs As CellStyle = _flex.Styles.Add("Lock")
                        cs.DataType = GetType(String)


                        .Cols(i + 1).Style = cs
                        .Cols(i + 1).AllowEditing = False
                        .Cols(i + 1).TextAlign = TextAlignEnum.LeftCenter

                        If vLockColor = 1 Then
                            cs.BackColor = Color.AliceBlue
                            cs.ForeColor = Color.MidnightBlue
                        End If
                    End If

                    If vFldDt.Rows(i)("Col_CheckBox").ToString = "1" Then
                        Dim cs As CellStyle = _flex.Styles.Add("bool")
                        cs.DataType = GetType(Boolean)
                        cs.ImageAlign = ImageAlignEnum.CenterCenter

                        .Cols(i + 1).Style = cs

                    End If

                Next

            End With

        End Sub
        ''' <summary>
        ''' 创建时间：2017/4/16
        ''' 说明：表格列项绑定组件，当前是绑定c1combo    
        ''' </summary>
        ''' <param name="vColumnName">所在列项名</param>
        ''' <param name="vCompotent">控件名</param>
        ''' <remarks></remarks>
        Public Sub BindComponent(ByVal vColumnName As String, ByVal vCompotent As Control)
            Dim vComcol As Column = _flex.Cols(vColumnName)
            vComcol.Editor = vCompotent

        End Sub
        ''' <summary>
        ''' 创建时间:2017/5/14
        ''' 说明：选择表格的主题类型  
        ''' </summary>
        ''' <param name="vTheme">主题类型</param>
        ''' <remarks></remarks>
        Public Sub SelectTheme(ByVal vTheme As Theme)
            Select Case vTheme
                Case Theme.Office2003
                    Office2003(_flex.Styles)
                Case Theme.Office12
                    Office12(_flex.Styles)
                Case Theme.Office10Blue '2018.1.22
                    Office10Blue(_flex.Styles)
            End Select
        End Sub
        ''' <summary>
        ''' 创建时间:2017/7/19
        ''' 说明：选择表格的主题类型  
        ''' </summary>
        ''' <param name="vFlex">c1flexgrid控件</param>
        ''' <param name="vTheme">主题类型</param>
        ''' <remarks></remarks>
        Public Sub SelectTheme(ByVal vFlex As C1FlexGrid, ByVal vTheme As Theme)
            Select Case vTheme
                Case Theme.Office2003
                    Office2003(vFlex.Styles)
                Case Theme.Office12
                    Office12(vFlex.Styles)
            End Select
        End Sub
        ''' <summary>
        ''' 创建时间：2017/5/14
        ''' 说明：设置表格的主题为office2003样式  
        ''' </summary>
        ''' <param name="s">表格样式集</param>
        ''' <remarks></remarks>
        Private Sub Office2003(s As CellStyleCollection)
            s.Clear()

            s.Normal.Border.Color = Color.FromArgb(180, 180, 180)              ' = SystemColors.InactiveBorder
            s.Highlight.Clear()
            s.Highlight.BackColor = SystemColors.GradientInactiveCaption
            s.SelectedColumnHeader.BackColor = Color.FromArgb(54, 89, 152) '  System.Windows.Forms.VisualStyles.VisualStyleInformation.ControlHighlightHot
            s.SelectedColumnHeader.ForeColor = Color.FromArgb(254, 254, 254)
            s.SelectedRowHeader.MergeWith(s.SelectedColumnHeader)
            s.EmptyArea.BackColor = Color.FromArgb(246, 246, 246)
            s.EmptyArea.Border.Color = Color.FromArgb(246, 246, 246)
            s.Editor.Border.Color = Color.FromArgb(180, 180, 180)
            s.Focus.BackColor = Color.FromArgb(54, 89, 152)
            s.Focus.ForeColor = Color.FromArgb(240, 240, 240)


        End Sub
        ''' <summary>
        ''' 创建时间：2018.1.22
        ''' 说明：office10版本blue样式  
        ''' </summary>
        ''' <param name="s"></param>
        ''' <remarks></remarks>
        Private Sub Office10Blue(s As CellStyleCollection)
            s.Clear()
            '   s.Normal.Font= new Font("Microsoft YaHei UI", 9.07563!)
            s.Normal.Border.Color = Color.FromArgb(180, 180, 180)              ' = SystemColors.InactiveBorder
            s.Highlight.Clear()
            s.Highlight.BackColor = Color.FromArgb(183, 219, 255) 'SystemColors.GradientInactiveCaption
            s.SelectedColumnHeader.BackColor = Color.FromArgb(231, 240, 250) '  System.Windows.Forms.VisualStyles.VisualStyleInformation.ControlHighlightHot
            s.SelectedColumnHeader.ForeColor = Color.Black
            s.SelectedRowHeader.MergeWith(s.SelectedColumnHeader)
            s.Fixed.BackColor = Color.FromArgb(231, 240, 250)
            s.EmptyArea.BackColor = Color.AliceBlue
            s.EmptyArea.Border.Color = Color.FromArgb(246, 246, 246)
            s.Editor.Border.Color = Color.FromArgb(180, 180, 180)
            s.Focus.BackColor = Color.FromArgb(54, 89, 152)
            s.Focus.ForeColor = Color.FromArgb(240, 240, 240)
        End Sub
        ''' <summary>
        ''' 创建时间：2017/5/14
        ''' 说明：office12版本样式  
        ''' </summary>
        ''' <param name="s"></param>
        ''' <remarks></remarks>
        Private Sub Office12(s As CellStyleCollection)
            Office2003(s)

            s.Highlight.BackColor = Color.FromArgb(180, s.Highlight.BackColor)

            Dim cs As CellStyle = s.Fixed
            cs.BackgroundImage = BuildStyleBackground(s.Fixed.BackColor)
            cs.BackgroundImageLayout = ImageAlignEnum.TileStretch
            cs.BackColor = Color.White


            cs = s.SelectedColumnHeader
            cs.BackgroundImage = BuildStyleBackground(s.SelectedColumnHeader.BackColor)
            cs.BackColor = Color.FromArgb(54, 89, 152)
            cs.BackgroundImageLayout = ImageAlignEnum.TileStretch
            cs.BackColor = Color.White

            cs = s.SelectedRowHeader
            cs.Clear()
            cs.MergeWith(s.SelectedColumnHeader)
            cs = s.EmptyArea
            cs.Clear()
            cs.BackgroundImage = BuildStyleBackground(s.SelectedColumnHeader.BackColor)
            cs.BackgroundImageLayout = ImageAlignEnum.TileStretch
            cs.BackColor = Color.White
            s.Normal.Font = New Font("Microsoft YaHei UI", 9.07563!)
            s.EmptyArea.BackColor = Color.FromArgb(246, 246, 246)
            s.EmptyArea.Border.Color = Color.FromArgb(246, 246, 246)
            s.Normal.Border.Color = Color.FromArgb(180, 180, 180)
            s.Focus.BackColor = Color.FromArgb(54, 89, 152)
            s.Focus.ForeColor = Color.FromArgb(240, 240, 240)
        End Sub
        Private Function BuildStyleBackground(background As Color) As Bitmap
            Return BuildStyleBackground(Color.FromArgb(150, background), background, 90.0F)
        End Function

        Private Function BuildStyleBackground(color1 As Color, color2 As Color, angle As Single) As Bitmap
            Dim rc As New Rectangle(0, 0, 10, 15)
            Dim bmp As New Bitmap(rc.Width, rc.Height)
            Using g As Graphics = Graphics.FromImage(bmp)
                Using br As New LinearGradientBrush(rc, color1, color2, angle)
                    g.FillRectangle(br, rc)
                End Using
            End Using
            Return bmp
        End Function
        ''' <summary>
        ''' 创建时间：2017/5/20
        ''' 说明：输出excel  
        ''' </summary>
        ''' <param name="vFileFlag">文件保存格式类型</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Overridable Function ExportExcel(ByVal vFileFlag As FileFlags) As Integer
            Dim intsuc As Integer
            intsuc = 0
            Try

                Dim dlg As New SaveFileDialog
                dlg.Filter = "Excel2003 (*.xls)|*.xls|Excel2007 (*.xlsx)|*.xlsx"

                If dlg.ShowDialog() <> DialogResult.OK Then
                    intsuc = 0
                Else
                    _flex.SaveGrid(dlg.FileName, FileFormatEnum.Excel, vFileFlag)
                    intsuc = 1
                End If
            Catch ex As Exception
                Throw New Exception(ex.Message)
                intsuc = 0
            End Try
            Return intsuc
        End Function


        ''' <summary>
        ''' 创建时间：2017/6/28
        ''' 说明：从数据源datatable提取数据覆盖到表格c1flexgrid中,覆盖成功返回1，否则=0      
        ''' </summary>
        ''' <param name="flex">c1flexgrid表格控件</param>
        ''' <param name="vDt">数据来源datatable</param>
        ''' <returns>覆盖成功返回1，否则=0</returns>
        ''' <remarks></remarks>
        Public Shared Function ImportDbDtFillData(ByVal flex As C1FlexGrid, ByVal vDt As DataTable) As Integer
            Dim intsuc As Integer = 0
            Dim intRow As Integer
            intRow = flex.Rows.Count
            For Each dr As DataRow In vDt.Rows
                flex.Rows.Add()

                For Each dc As DataColumn In vDt.Columns
                    For i As Integer = 0 To flex.Cols.Count - 1
                        If LCase(dc.ColumnName) = LCase(flex.Cols(i).Name) Then
                            flex.Rows(intRow)(dc.ColumnName) = dr(dc.ColumnName)
                        End If
                    Next
                Next
                intRow = intRow + 1
            Next
            Return intsuc
        End Function
        ''' <summary>
        ''' 创建时间：2017/6/28
        ''' 说明：从数据源datatable提取数据覆盖到表格c1flexgrid中,覆盖成功返回1，否则=0   
        ''' </summary>
        ''' <param name="vDt">数据来源表</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function ImportDbDtFillData(ByVal vDt As DataTable) As Integer
            Dim intsuc As Integer = 0
            Dim intRow As Integer
            intRow = _flex.Rows.Count
            For Each dr As DataRow In vDt.Rows
                _flex.Rows.Add()

                For Each dc As DataColumn In vDt.Columns
                    For i As Integer = 0 To _flex.Cols.Count - 1
                        If LCase(dc.ColumnName) = LCase(_flex.Cols(i).Name) Then
                            _flex.Rows(intRow)(dc.ColumnName) = dr(dc.ColumnName)
                            _flex.Cols(dc.ColumnName).TextAlign = TextAlignEnum.LeftCenter
                        End If
                    Next
                Next
                intRow = intRow + 1
            Next
            Return intsuc
        End Function
        ''' <summary>
        ''' 创建时间：2017/9/30
        ''' 说明：把c1flexgrid表格数据打包到dataTable表     
        ''' </summary>
        ''' <param name="vFlex">对应c1flexgrid</param>
        ''' <param name="IsTotSum">表格是否有合计值。如果是合计值，则=1.另外合计值默认在第一行</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Shared Function GetDataTable(ByVal vFlex As C1FlexGrid, Optional ByVal IsTotSum As Integer = 0) As DataTable
            Dim dt As New DataTable
            Try
                dt.Clear()
                With vFlex
                    For j As Integer = 1 To .Cols.Count - 1
                        dt.Columns.Add(vFlex.Cols(j).Name)
                    Next
                    For i As Integer = 1 + IsTotSum To .Rows.Count - 1
                        dt.Rows.Add()
                        For j = 1 To .Cols.Count - 1
                            dt.Rows(i - 1 - IsTotSum)(j - 1) = vFlex.Rows(i)(j)
                        Next
                    Next
                End With

            Catch ex As Exception
                MsgBox(ex.Message, , "错误")
            End Try
            Return dt
        End Function

#End Region
#Region "表格合计值计算"
        ''' <summary>
        ''' 创建时间：2017/6/20
        ''' 说明：返回c1flexgrid某列的合计值，并且合计值列项隐藏  
        ''' </summary>
        ''' <param name="vFldName">字段名</param>
        ''' <returns>返回指定的某列合计值</returns>
        ''' <remarks></remarks>
        Public Overloads Function FormulaSumTotal(ByVal vFldName As String) As Double
            Dim dblsuc As Double = 0
            Try
                Dim intcol As Integer
                intcol = _flex.Cols(vFldName).Index
                _flex.Subtotal(AggregateEnum.Sum, -1, -1, intcol)
                _flex.Rows(1).Visible = False
                dblsuc = Convert.ToDouble(_flex.Rows(1)(intcol).ToString())
            Catch ex As Exception
                MErrMessage = ex.Message
            End Try
            Return dblsuc
        End Function
        ''' <summary>
        ''' 创建时间：2017/5/26
        ''' 说明：提取合计值列项并且绑定数据源这些列项进行计算  
        ''' </summary>
        ''' <param name="vModuleName">模块名</param>
        ''' <param name="vConnection">数据库链接字符串</param>
        ''' <param name="vSumIsVisible">隐藏合计值，默认=0，隐藏；1=不隐藏</param>
        ''' <returns>返回是否合计值计算成功。1=成功，0=不成功</returns>
        ''' <remarks></remarks>
        Public Overloads Function FormulaSumTotal(ByVal vModuleName As String, ByVal vConnection As String, Optional ByVal vSumIsVisible As Integer = 0) As Integer
            Dim intsuc As Integer
            intsuc = 0
            Try
                Dim dtsum As New DataTable
                dtsum = ColumnIsSum(vModuleName, vConnection)
                For Each dr As DataRow In dtsum.Rows
                    _flex.Subtotal(AggregateEnum.Sum, -1, -1, _flex.Cols(dr("col_fieldname").ToString()).Index)
                Next
                _flex.Rows(1).Visible = vSumIsVisible
                intsuc = 1
            Catch ex As Exception
                MErrMessage = "合计值计算失败，失败原因:" + vbCrLf + ex.Message
            End Try
            Return intsuc
        End Function
        ''' <summary>
        ''' 创建时间：2017/7/19
        ''' 说明：提取合计值列项并且绑定数据源这些列项进行计算  
        ''' </summary>
        ''' <param name="vflex">c1flexgrid控件</param>
        ''' <param name="vModuleName">模块名</param>
        ''' <param name="vConnection">数据库链接字符串</param>
        ''' <param name="vSumIsVisible">隐藏合计值，默认=0，隐藏；1=不隐藏</param>
        ''' <returns>返回是否合计值计算成功。1=成功，0=不成功</returns>
        ''' <remarks></remarks>
        Public Overloads Function FormulaSumTotal(ByVal vFlex As C1FlexGrid, ByVal vModuleName As String, ByVal vConnection As String, Optional ByVal vSumIsVisible As Integer = 0) As Integer
            Dim intsuc As Integer
            intsuc = 0
            Try
                Dim dtsum As New DataTable
                dtsum = ColumnIsSum(vModuleName, vConnection)
                For Each dr As DataRow In dtsum.Rows
                    vFlex.Subtotal(AggregateEnum.Sum, -1, -1, vFlex.Cols(dr("col_fieldname").ToString()).Index)
                Next
                vFlex.Rows(1).Visible = vSumIsVisible
                intsuc = 1
            Catch ex As Exception
                MErrMessage = "合计值计算失败，失败原因:" + vbCrLf + ex.Message
            End Try
            Return intsuc
        End Function
        ''' <summary>
        ''' 创建时间：2017/5/27
        ''' 说明：在制定的窗体中对c1flexgrid表格合计值进行复制操作，把合计值赋值到c1textbox控件上    
        ''' 每个c1textbox控件要设置tag与c1flexgrid对应列项字段保持一致才可以赋值成功  
        ''' </summary>
        ''' <param name="vModuleName">模板名</param>
        ''' <param name="vControlCollection">control集合一般指窗体控件集合或者特定容器控件集合</param>
        ''' <param name="vConnection">数据库链接字符串</param>
        ''' <returns>返回是否赋值成功。1=成功，0=失败</returns>
        ''' <remarks></remarks>
        Public Overloads Function FormTotalFormula(ByVal vModuleName As String, ByVal vControlCollection As Control.ControlCollection, ByVal vConnection As String) As Integer
            Dim intsuc As Integer
            intsuc = 0

            Try
                '//合计值提取

                intsuc = FormulaSumTotal(vModuleName, vConnection)
                If intsuc = 1 Then
                    For Each vControl As Control In vControlCollection
                        If TypeOf vControl Is C1TextBox Or TypeOf vControl Is DevExpress.XtraEditors.TextEdit Then
                            Dim str As String
                            str = vControl.Name
                            If str.Substring(0, 5).ToLower = "c1sum" Then
                                vControl.Text = "0"
                                If _flex.Rows.Count >= 2 Then
                                    vControl.Text = _flex(1, vControl.Tag)

                                End If
                            End If
                        End If
                    Next
                    intsuc = 1
                End If

            Catch ex As Exception
                MErrMessage = "表格合计值赋值窗体控件失败，失败原因:" + vbCrLf + ex.Message
            End Try
            Return intsuc
        End Function

#End Region
#Region "表格样式设置函数及事件"
        ''' <summary>
        ''' 2021.6.16
        ''' </summary>
        ''' <param name="vfg"></param>
        ''' <param name="vRow"></param>
        ''' <param name="vcol"></param>
        Public Shared Sub CellSetRedFont(ByVal vfg As C1FlexGrid, ByVal vRow As Integer, ByVal vcol As Integer)
            Dim cs As CellStyle = vfg.Styles.Add("redfont")
            cs.ForeColor = Color.FromArgb(255, 0, 0)
            vfg.SetCellStyle(vRow, vcol, cs)
        End Sub
        ''' <summary>
        ''' 创建时间：2017/12/2
        ''' 说明：设置指定的行Row为红色字体      
        ''' </summary>
        ''' <param name="vfg">c1flexgrid表格</param>
        ''' <param name="vRow">哪一行</param>
        ''' <remarks></remarks>
        Public Shared Sub CellSetRedFont(ByVal vfg As C1FlexGrid, ByVal vRow As Integer)
            Dim cs As CellStyle = vfg.Styles.Add("redfont")
            cs.ForeColor = Color.FromArgb(255, 0, 0)
            vfg.Rows(vRow).Style = cs

        End Sub
        ''' <summary>
        ''' 创建时间：2017/12/2
        ''' 说明：设置指定的行Row为蓝色字体    
        ''' </summary>
        ''' <param name="vfg"></param>
        ''' <param name="vRow"></param>
        ''' <remarks></remarks>
        Public Shared Sub CellSetBlueFont(ByVal vfg As C1FlexGrid, ByVal vRow As Integer)
            Dim cs As CellStyle = vfg.Styles.Add("bluefont")
            cs.ForeColor = Color.FromArgb(0, 0, 255)
            vfg.Rows(vRow).Style = cs
        End Sub
        ''' <summary>
        ''' 2021.6.16
        ''' 单元格字体还原。
        ''' </summary>
        ''' <param name="vfg"></param>
        ''' <param name="vRow">所在行</param>
        ''' <param name="vCol">所在列</param>
        Public Shared Sub CellInitialColor(ByVal vfg As C1FlexGrid, ByVal vRow As Integer, ByVal vCol As Integer)
            Dim orics As CellStyle = vfg.Styles.Add("orifont")
            orics.ForeColor = Color.FromArgb(0, 0, 0)
            If vRow = -1 Then
                vfg.Cols(vCol).Style = orics
            Else
                vfg.SetCellStyle(vRow, vCol, orics)
            End If

        End Sub
        ''' <summary>
        ''' 2020.10.8
        ''' 说明：对于c1flexgrid表格的指定行，进行颜色初始化
        ''' </summary>
        ''' <param name="vfg"></param>
        ''' <param name="vRow">所在行，默认行是-1</param>
        Public Shared Sub RowInitialColor(ByVal vfg As C1FlexGrid, Optional ByVal vRow As Integer = -1)
            Dim orics As CellStyle = vfg.Styles.Add("orifont")
            orics.ForeColor = Color.FromArgb(0, 0, 0)
            vfg.Rows(vRow).Style = orics
        End Sub
        ''' <summary>
        ''' 2018.1.24
        ''' 说明：对于指定的只读单元格进行背景颜色设置       
        ''' </summary>
        ''' <param name="vfg">c1flexgrid</param>
        ''' <param name="vRow">行号。如果-1，则默认某列背景颜色</param>
        ''' <param name="vCol">列号，如果是-1，则默认某行背景颜色</param>
        ''' <param name="vFontBold">是否默认字体粗体，默认不是</param>
        ''' <remarks></remarks>
        Public Shared Sub CellLockBackColor(ByVal vfg As C1FlexGrid, ByVal vRow As Integer, ByVal vCol As Integer, Optional ByVal vFontBold As Boolean = False)
            Dim cs As CellStyle = vfg.Styles.Add("Lockcellback")
            cs.BackColor = Color.AliceBlue
            cs.ForeColor = Color.MidnightBlue
            If vFontBold = True Then
                cs.Font = New Font("Verdana", 9, FontStyle.Bold)
            End If
            If vRow <= 0 And vCol <= 0 Then
                Exit Sub
            End If
            If vRow = -1 Then
                '某列设置背景颜色
                vfg.Cols(vCol).Style = cs
            ElseIf vCol = -1 Then
                '某行
                vfg.Rows(vRow).Style = cs
            Else
                vfg.SetCellStyle(vRow, vCol, cs)
            End If

            vfg.Rows(vRow).Style = cs
        End Sub
        ''' <summary>
        ''' 2021.6.16
        ''' 绑定的列项，背景颜色和字体复原
        ''' </summary>
        ''' <param name="vfg"></param>
        ''' <param name="vEndCol">截止到那个列项，从第一列开始算起</param>
        ''' <param name="vRedo">=false,默认还原，=true 默认撤销绑定时的背景色和字体样式</param>
        Public Shared Sub BindColToCellStyle(ByVal vfg As C1FlexGrid, Optional ByVal vEndCol As Integer = 1, Optional ByVal vRedo As Boolean = False)
            Dim cs As CellStyle
            If vRedo = False Then
                cs = vfg.Styles.Add("bindbackcolor")
                cs.BackColor = Color.AliceBlue
                cs.ForeColor = Color.MidnightBlue
            Else
                cs = vfg.Styles.Add("Redobackcolor")
                '      cs.BackColor = Color.White
                cs.ForeColor = Color.FromArgb(0, 0, 0)
            End If

            For i As Integer = 1 To vEndCol
                '                .Cols(i + 1).DataType = GetType(String)
                '                .Cols(i + 1).AllowEditing = False
                '                .Cols(i + 1).TextAlign = TextAlignEnum.LeftCenter
                If vfg.Cols(i).AllowEditing = False Then
                    vfg.Cols(i).Style = cs

                End If
            Next
        End Sub
        ''' <summary>
        ''' 2018.1.24
        ''' 说明：对于指定的只读单元格进行背景颜色设置       
        ''' </summary>
        ''' <param name="vfg">c1flexgrid</param>
        ''' <param name="vRow">行号。如果-1，则默认某列背景颜色</param>
        ''' <param name="vCol">列号，如果是-1，则默认某行背景颜色</param>
        ''' <param name="vBackColor">背景颜色</param>
        ''' <param name="vFontBold">是否默认字体粗体，默认不是</param>
        ''' <remarks></remarks>
        Public Shared Sub CellLockBackColor(ByVal vfg As C1FlexGrid, ByVal vRow As Integer, ByVal vCol As Integer, ByVal vBackColor As Color, Optional ByVal vFontBold As Boolean = False)
            Dim cs As CellStyle = vfg.Styles.Add("Lockcellback")
            cs.BackColor = vBackColor
            cs.ForeColor = Color.MidnightBlue
            If vFontBold = True Then
                cs.Font = New Font("Verdana", 9, FontStyle.Bold)
            End If
            If vRow <= 0 And vCol <= 0 Then
                Exit Sub
            End If
            If vRow = -1 Then
                '某列设置背景颜色
                vfg.Cols(vCol).Style = cs
            ElseIf vCol = -1 Then
                '某行
                vfg.Rows(vRow).Style = cs
            Else
                vfg.SetCellStyle(vRow, vCol, cs)
            End If

            vfg.Rows(vRow).Style = cs
        End Sub

        ''' <summary>
        ''' 创建时间：2017/12/2
        ''' 说明：设置单元格字体颜色样式        
        ''' </summary>
        ''' <param name="vFg">c1flexgrid表格</param>
        ''' <param name="vStyleName">样式名称</param>
        ''' <param name="vColor">颜色</param>
        ''' <returns></returns>
        ''' <remarks></remarks>
        Public Function CellStyleFontColor(ByVal vFg As C1FlexGrid, ByVal vStyleName As String, ByVal vColor As Color) As CellStyle
            Dim cs As CellStyle = vFg.Styles.Add(vStyleName)
            cs.ForeColor = vColor
            Return cs
        End Function
        ''' <summary>
        ''' 2021.4.16
        ''' 行的单元格自动换行
        ''' </summary>
        ''' <param name="vFg">c1flexgrid</param>
        ''' <param name="vRow">所在的行，如果是-1，则表明是所有行</param>
        Public Sub RowAutoWordWrap(ByVal vFg As C1FlexGrid, ByVal vRow As Integer)
            Try
                Dim cs As CellStyle = vFg.Styles.Add("wordwrap")
                cs.WordWrap = True '设置自动换行
                If vRow = -1 Then
                    '所有行，换行
                    For i As Integer = 1 To vFg.Rows.Count - 1
                        vFg.Rows(i).Style = cs
                        vFg.AutoSizeRow(i) '自动适应大小
                    Next
                Else
                    vFg.Rows(vRow).Style = cs
                    vFg.AutoSizeRow(vRow)
                End If
            Catch ex As Exception

            End Try
        End Sub
        ''' <summary>
        ''' 2021.7.18
        ''' 对某一行进行的数字类型的列，初始化，默认填充0
        ''' </summary>
        ''' <param name="vSelectRow">选择的行</param>
        Public Sub RowInitialFillNums(ByVal vSelectRow As Integer)
            For j As Integer = 1 To _flex.Cols.Count - 1
                If _flex.Cols(j).DataType = GetType(Decimal) Then
                    _flex.Rows(vSelectRow)(j) = 0
                End If
            Next

        End Sub

#End Region
#Region "cell单元各类型"
        ''' <summary>
        ''' 2020.3.18
        ''' 设置某列的单元格为combolist格式，
        ''' </summary>
        ''' <param name="vfg">c1flexgrid对象</param>
        ''' <param name="vComBoList">combolist格式，格式样式"|a|b|c"</param>
        ''' <param name="vSelCols">选择那列设置成combolist</param>
        Public Sub CellSetCombo(ByVal vfg As C1FlexGrid, ByVal vComBoList As String, ByVal vSelCols As Integer)
            Dim cs As CellStyle = vfg.Styles.Add("cbo")
            cs.DataType = GetType(String)
            cs.ComboList = vComBoList
            Dim rg As CellRange = vfg.GetCellRange(1, vSelCols, vfg.Rows.Count - 1, vSelCols)
            rg.Style = vfg.Styles("cbo")
        End Sub
        ''' <summary>
        ''' 2020.3.18
        ''' 设置某个区间的单元格为combolist格式，
        ''' </summary>
        ''' <param name="vfg">c1flexgrid对象</param>
        ''' <param name="vComBoList">combolist格式，格式样式"|a|b|c"</param>
        ''' <param name="vLeftrows">起始行号</param>
        ''' <param name="vleftcols">起始列号</param>
        ''' <param name="vbottomrows">结束行号</param>
        ''' <param name="vbottomcols">结束列号</param>
        Public Sub CellSetCombo(ByVal vfg As C1FlexGrid, ByVal vComBoList As String, ByVal vLeftrows As Integer, ByVal vleftcols As Integer, ByVal vbottomrows As Integer, ByVal vbottomcols As Integer)
            Dim cs As CellStyle = vfg.Styles.Add("cbo")
            cs.DataType = GetType(String)
            cs.ComboList = vComBoList
            Dim rg As CellRange = vfg.GetCellRange(vLeftrows, vleftcols, vbottomrows, vbottomcols)
            rg.Style = vfg.Styles("cbo")
        End Sub
#End Region
#Region "其他操作"
        ''' <summary>
        ''' 2021.6.3
        ''' 鼠标单击单元格时，全选文字，应用到c1flexgrid.MouseClick事件
        ''' </summary>
        ''' <param name="sender"></param>
        ''' <param name="e"></param>
        Public Sub MouseClickSelectAllText(sender As Object, e As MouseEventArgs)
            Dim ht As HitTestInfo = _flex.HitTest(e.X, e.Y)
            If ht.Row >= 1 And ht.Column >= 1 Then
                If _flex.Cols(ht.Column).DataType <> GetType(Boolean) And _flex.Cols(ht.Column).AllowEditing = True Then

                    _flex.StartEditing()
                End If

            End If
        End Sub
        ''' <summary>
        ''' 2021.7.18
        ''' 对于某列值，直接赋值
        ''' </summary>
        ''' <param name="vColumnName">列名</param>
        ''' <param name="vValue">需要覆盖的列值</param>
        ''' <param name="vSelectHideRow">默认隐藏列不覆盖，false表明覆盖</param>
        ''' <returns></returns>
        Public Function SelectAllRowSetColValue(ByVal vColumnName As String, ByVal vValue As String, Optional ByVal vSelectHideRow As Boolean = True) As Integer
            Dim intsuc As Integer = 0
            Try
                With _flex
                    For i As Integer = 1 To .Rows.Count - 1
                        If vSelectHideRow = True Then
                            _flex.Rows(i)(vColumnName) = vValue
                        Else
                            '隐藏列可以默认不勾选 2018.8.18
                            If _flex.Rows(i).Visible = True Then
                                _flex.Rows(i)(vColumnName) = vValue
                            End If
                        End If


                    Next
                End With
                intsuc = 1
            Catch ex As Exception
                MsgBox(ex.Message)
            End Try
            Return intsuc
        End Function
#End Region
    End Class
End Namespace
